package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import bean.funcaoBean;

public class funcaoDao {

//	public void inserir(Connection conn, funcaoBean funcao) throws SQLException {
//
//		String sql = "insert into funcao(nome) values(?)";
//
//		PreparedStatement ps = conn.prepareStatement(sql);
//		ps.setString(1, funcao.getNome());
//		ps.execute();
//		ps.close();
//	}
//
//	public void alterar(Connection conn, funcaoBean funcao) throws SQLException {
//
//		String sql = "update funcao set nome = ? where id = ?";
//
//		PreparedStatement ps = conn.prepareStatement(sql);
//		ps.setString(1, funcao.getNome());
//		ps.setInt(2, funcao.getId());
//		ps.execute();
//		ps.close();
//	}
//
//	public void remover(Connection conn, funcaoBean funcao) throws SQLException {
//
//		String sql = "delete from funcao where id = ?";
//
//		PreparedStatement ps = conn.prepareStatement(sql);
//		ps.setInt(1, funcao.getId());
//		ps.execute();
//		ps.close();
//	}

	public ArrayList<funcaoBean> getLista(Connection conn) throws SQLException {

		String sql = "select * from funcao where id <> 6 order by id";

		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();
		ArrayList<funcaoBean> funcaos = new ArrayList<funcaoBean>();
		while (rs.next()) {
			funcaoBean funcao = new funcaoBean();
			funcao.setId(rs.getInt("id"));
			funcao.setNome(rs.getString("nome"));
			funcaos.add(funcao);
		}
		ps.close();
		rs.close();

		return funcaos;

	}

	public funcaoBean getfuncao(Connection conn, funcaoBean funcaoBean)
			throws SQLException {

		String sql = "select * from funcao where id = ?";

		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, funcaoBean.getId());

		ResultSet rs = ps.executeQuery();

		funcaoBean funcao = new funcaoBean();
		if(rs.next()){
		funcao.setId(rs.getInt("id"));
		funcao.setNome(rs.getString("nome"));
		}
		ps.close();
		rs.close();

		return funcao;

	}

}
